package top.xin1901.j2ecd.beans;

import lombok.Data;
import top.xin1901.j2ecd.beans.dbo.PermissionDbO;
import top.xin1901.j2ecd.beans.dbo.RoleDbO;
import top.xin1901.j2ecd.dao.RoleDao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author HeYunjia
 */

@Data
public class Role {
    private Long roleId;
    private String roleName;
    private String roleComment;
    private Date gmtCreate;
    private Date gmtModified;

    private List<PermissionDbO> permissions;

    public RoleDbO toRoleDbO() {
        RoleDbO roleDbO = new RoleDbO();

        roleDbO.setRoleName(this.getRoleName());
        roleDbO.setRoleComment(this.getRoleComment());
        roleDbO.setGmtCreate(this.getGmtCreate());
        roleDbO.setGmtModified(this.getGmtModified());

        return roleDbO;
    }

    public List<Long> toPermissionIds() {
        if (this.permissions == null) return null;
        List<Long> longs = new ArrayList<>();

        for (PermissionDbO p : this.getPermissions()) {
            longs.add(p.getPermissionId());
        }
        return longs;
    }
}
